Telegram Group & Telegram Channel
Ну что, за два дня готов пакет для построения AST для protobuf 👩‍💻 butschster/proto-parser . Уверен всплывут баги и т.д., но тесты есть, кучу edge кейсов покрыл.

Чем он крут? Можно взять proto-файлы, превратить их в дерево PHP-объектов (AST) и далее сгенерировать свои DTO-классы. Например:

syntax = "proto3";

package examplepb;

message Person {
// Unique identifier for the person.
uint64 id = 1 [(validate.rules).uint64.gt = 999];

// Email address will be used for communication.
string email = 2 [(validate.rules).string.email = true];

// Full name of the person.
string name = 3 [(validate.rules).string = {
pattern: "^[A-Za-z]+( [A-Za-z]+)*$",
max_bytes: 256
}];

// Home location of the person.
Location home = 4 [(validate.rules).message.required = true];

message Location {
double lat = 1 [(validate.rules).double = {gte: -90, lte: 90}];
double lng = 2 [(validate.rules).double = {gte: -180, lte: 180}];
}
}

service ExampleService {
// Create a new person.
rpc CreatePerson(Person) returns (Person) {
option (google.api.http) = {
post: "/v1/persons"
body: "*"
};
}
}


Превратим в:

use Symfony\Component\Validator\Constraints as Assert;

final readonly class Person
{
public function __construct(
/** Unique identifier for the person. */
#[Assert\GreaterThan(value: 999)]
public int $id,
/** Email address will be used for communication. */
#[Assert\Email]
public string $email,
/** Full name of the person. */
#[Assert\Regex(pattern: '^[A-Za-z]+( [A-Za-z]+)*$'), Assert\Length(max: 256, charset: '8bit')]
public string $name,
/** Home location of the person. */
#[Assert\NotNull]
public Location $home,
) {
}
}


use Symfony\Component\Validator\Constraints as Assert;

final readonly class Location
{
public function __construct(
#[Assert\GreaterThanOrEqual(value: -90), Assert\LessThanOrEqual(value: 90)]
public float $lat,
#[Assert\GreaterThanOrEqual(value: -180), Assert\LessThanOrEqual(value: 180)]
public float $lng,
) {
}
}


<?php

declare(strict_types=1);

namespace Internal;

use App\Grpc\Service;
use OpenApi\Annotations as OA;
use Spiral\RoadRunner\GRPC\ContextInterface;

#[Service(name: 'ExampleService', package: 'examplepb')]
interface ExampleServiceInterface
{
/**
* Create a new person.
*/
#[OA\Post(path: '/v1/persons', tags: ['CreatePerson'])]
#[OA\RequestBody(path: '*', tags: ['CreatePerson'])]
public function CreatePerson(ContextInterface $ctx, Person $in): Person;
}




Что умеет:
1. Строить дерево. Понимает весь синтаксис, что я смог найти.
2. Привязывать комментарии к нодам. Например комментарий над полем будет в ноде поля. Комментарий к option будет в его ноде. И т.д.
3. Дока есть.

Что не умеет:
ХЗ что. призываю потестить и улучшить желающих.

Прогнал свой проект с > 100 proto файлов, все спарсил.

P.s. Ах да, забыл сказать, что эти DTO сгененировал мой другой пакет, который уже умеет работать с AST. Сделан на коленке, поэтому еще не выкладывал.
Please open Telegram to view this post
VIEW IN TELEGRAM
3🔥30



tg-me.com/php_fart/100
Create:
Last Update:

Ну что, за два дня готов пакет для построения AST для protobuf 👩‍💻 butschster/proto-parser . Уверен всплывут баги и т.д., но тесты есть, кучу edge кейсов покрыл.

Чем он крут? Можно взять proto-файлы, превратить их в дерево PHP-объектов (AST) и далее сгенерировать свои DTO-классы. Например:

syntax = "proto3";

package examplepb;

message Person {
// Unique identifier for the person.
uint64 id = 1 [(validate.rules).uint64.gt = 999];

// Email address will be used for communication.
string email = 2 [(validate.rules).string.email = true];

// Full name of the person.
string name = 3 [(validate.rules).string = {
pattern: "^[A-Za-z]+( [A-Za-z]+)*$",
max_bytes: 256
}];

// Home location of the person.
Location home = 4 [(validate.rules).message.required = true];

message Location {
double lat = 1 [(validate.rules).double = {gte: -90, lte: 90}];
double lng = 2 [(validate.rules).double = {gte: -180, lte: 180}];
}
}

service ExampleService {
// Create a new person.
rpc CreatePerson(Person) returns (Person) {
option (google.api.http) = {
post: "/v1/persons"
body: "*"
};
}
}


Превратим в:

use Symfony\Component\Validator\Constraints as Assert;

final readonly class Person
{
public function __construct(
/** Unique identifier for the person. */
#[Assert\GreaterThan(value: 999)]
public int $id,
/** Email address will be used for communication. */
#[Assert\Email]
public string $email,
/** Full name of the person. */
#[Assert\Regex(pattern: '^[A-Za-z]+( [A-Za-z]+)*$'), Assert\Length(max: 256, charset: '8bit')]
public string $name,
/** Home location of the person. */
#[Assert\NotNull]
public Location $home,
) {
}
}


use Symfony\Component\Validator\Constraints as Assert;

final readonly class Location
{
public function __construct(
#[Assert\GreaterThanOrEqual(value: -90), Assert\LessThanOrEqual(value: 90)]
public float $lat,
#[Assert\GreaterThanOrEqual(value: -180), Assert\LessThanOrEqual(value: 180)]
public float $lng,
) {
}
}


<?php

declare(strict_types=1);

namespace Internal;

use App\Grpc\Service;
use OpenApi\Annotations as OA;
use Spiral\RoadRunner\GRPC\ContextInterface;

#[Service(name: 'ExampleService', package: 'examplepb')]
interface ExampleServiceInterface
{
/**
* Create a new person.
*/
#[OA\Post(path: '/v1/persons', tags: ['CreatePerson'])]
#[OA\RequestBody(path: '*', tags: ['CreatePerson'])]
public function CreatePerson(ContextInterface $ctx, Person $in): Person;
}




Что умеет:
1. Строить дерево. Понимает весь синтаксис, что я смог найти.
2. Привязывать комментарии к нодам. Например комментарий над полем будет в ноде поля. Комментарий к option будет в его ноде. И т.д.
3. Дока есть.

Что не умеет:
ХЗ что. призываю потестить и улучшить желающих.

Прогнал свой проект с > 100 proto файлов, все спарсил.

P.s. Ах да, забыл сказать, что эти DTO сгененировал мой другой пакет, который уже умеет работать с AST. Сделан на коленке, поэтому еще не выкладывал.

BY PHP Fart Time




Share with your friend now:
tg-me.com/php_fart/100

View MORE
Open in Telegram


PHP Fart Time Telegram | DID YOU KNOW?

Date: |

Telegram is riding high, adding tens of million of users this year. Now the bill is coming due.Telegram is one of the few significant social-media challengers to Facebook Inc., FB -1.90% on a trajectory toward one billion users active each month by the end of 2022, up from roughly 550 million today.

Telegram auto-delete message, expiring invites, and more

elegram is updating its messaging app with options for auto-deleting messages, expiring invite links, and new unlimited groups, the company shared in a blog post. Much like Signal, Telegram received a burst of new users in the confusion over WhatsApp’s privacy policy and now the company is adopting features that were already part of its competitors’ apps, features which offer more security and privacy. Auto-deleting messages were already possible in Telegram’s encrypted Secret Chats, but this new update for iOS and Android adds the option to make messages disappear in any kind of chat. Auto-delete can be enabled inside of chats, and set to delete either 24 hours or seven days after messages are sent. Auto-delete won’t remove every message though; if a message was sent before the feature was turned on, it’ll stick around. Telegram’s competitors have had similar features: WhatsApp introduced a feature in 2020 and Signal has had disappearing messages since at least 2016.

PHP Fart Time from sg


Telegram PHP Fart Time
FROM USA